package com.example.administrator.officeplatform.Audit;


import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.StringCodec;
import com.example.administrator.officeplatform.MyApplication;
import com.example.administrator.officeplatform.R;
import com.example.administrator.officeplatform.base.BaseActivity;
import com.example.administrator.officeplatform.bean.BearDepartmentVoInfo;
import com.example.administrator.officeplatform.bean.BorrowingVoInfo;
import com.example.administrator.officeplatform.bean.CostInfo;
import com.example.administrator.officeplatform.bean.PayeeInfo;
import com.example.administrator.officeplatform.bean.ReimbursementVoInfo;
import com.example.administrator.officeplatform.bean.RewardDeductionVoInfo;
import com.example.administrator.officeplatform.bean.TravelExpensesFormDetailVoInfo;
import com.example.administrator.officeplatform.kj.AuditorActivity;
import com.example.administrator.officeplatform.kj.IpUtil;
import com.example.administrator.officeplatform.kj.NoScrollView;
import com.example.administrator.officeplatform.utils.JsonUtil;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static com.example.administrator.officeplatform.R.id.ed_remarks;
import static com.example.administrator.officeplatform.R.id.tv_isWithholding;

/**
 *审核详情页面
 *@author Wangzhiqiang
 *Created on 2017/12/15 10:28
 */
public class AuditDetailActivity extends BaseActivity {
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.lay_main)
    LinearLayout lay_main;
    @Bind(R.id.layout_bearDepartment)
    LinearLayout layout_bearDepartment;
    @Bind(R.id.layout_ExpenseCostFormDetail)
    LinearLayout layout_ExpenseCostFormDetail;
    @Bind(R.id.layout_travelExpensesFormDetail)
    LinearLayout layout_travelExpensesFormDetail;
    @Bind(R.id.layout_rewardDeduction)
    LinearLayout layout_rewardDeduction;
    @Bind(R.id.layout_payee)
    LinearLayout layout_payee;
    @Bind(R.id.rv_ExpenseCostFormDetail)
    NoScrollView rv_ExpenseCostFormDetail;
    @Bind(R.id.rv_travelExpensesFormDetail)
    NoScrollView rv_travelExpensesFormDetail;
    @Bind(R.id.rv_bearDepartment)
    NoScrollView rv_bearDepartment;
    @Bind(R.id.rv_rewardDeduction)
    NoScrollView rv_rewardDeduction;
    @Bind(R.id.rv_payee)
    NoScrollView rv_payee;
    @Bind(R.id.layout_btn1)
    LinearLayout layout_btn1;
    @Bind(R.id.layout_btn2)
    LinearLayout layout_btn2;
    @Bind(R.id.layout_btn3)
    LinearLayout layout_btn3;
    @Bind(R.id.layout_btn6)
    LinearLayout layout_btn6;
    @Bind(R.id.layout_btn4)
    LinearLayout layout_btn4;
    @Bind(R.id.layout_shr)
    LinearLayout layout_shr;
    @Bind(R.id.layout_btn7)
    LinearLayout layout_btn7;
    private Context mContext;
    private List<AuditInfo> ls_audit;
    private Intent mIntent;
    private ReimbursementVoInfo reimbursementVoInfo = new ReimbursementVoInfo();
    private List<CostInfo> ls_ExpenseCostFormDetailVoInfo;
    private List<TravelExpensesFormDetailVoInfo> ls_TravelExpensesFormDetailVoInfo;
    private List<BearDepartmentVoInfo> ls_BearDepartmentVoInfo;
    private List<RewardDeductionVoInfo> ls_RewardDeductionVoInfo;
    private List<PayeeInfo> ls_PayeeInfo;
    private OkHttpClient mOkHttpClient= new OkHttpClient();
    private ProgressDialog mProgressDialog;
    private String who = "0";
    private String id,nextAuditorId,type;
    private TextView tv_shr,tv_shr1;
    private EditText ed_remarks;
    private View view;
    private ReimbursementVoInfo newInfo = new ReimbursementVoInfo();
    private DecimalFormat format = new DecimalFormat("0.00");

    @Override
    protected void setContentView() {
        setContentView(R.layout.audit_detail_activity);
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
        //设置布局管理器
        mContext=this;
    }

    @Override
    protected void initData() {
        mIntent = getIntent();

        ls_audit= new ArrayList<>();
        reimbursementVoInfo = (ReimbursementVoInfo) mIntent.getExtras().get(
                "ReimbursementVoInfo");
        who = (String) mIntent.getExtras().get(
                "who");
        id = reimbursementVoInfo.getId();
        getdata();
        type = reimbursementVoInfo.getReimbursementType();
        if(type.equals("expenseCost")){
            addExpenseCost();
        }else if(type.equals("travelExpense")){
            addTravelExpense();
        }else if(type.equals("borrowing")){
            addBorrowing();
        }else if(type.equals("rewardDeduction")){
            addRewardDeduction();
        }

        if (who.equals("1")){
            /**判断是否可以提交*/

            String processState =String.valueOf(reimbursementVoInfo.getProcessState());
            if (processState.equals("1")){
                showBtn3();
            }else if (processState.equals("5")){
                showBtn4();
            }

        }else if (who.equals("0")){
            /**判断是否可以审核驳回*/
            Boolean end = reimbursementVoInfo.isEnd();
            int myState  = reimbursementVoInfo.getMyState();
            int nodeType  = reimbursementVoInfo.getNodeType();

            if (end==false){
                if(myState==1) {
                    if (nodeType == 1) {
                        showBtn2();
                    } else if (nodeType == 2) {
                        showBtn1();
                    }

                }else if(myState==3){}

            }else if (end==true){
                if(myState==1){
                    if (nodeType == 1) {
                        showBtn7();
                    } else if (nodeType == 2) {
                        showBtn6();
                    }
                }
            }
        }


    }

    @Override
    protected void initEvents() {
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    
    /**
    *添加费用成本View
    *@author Wangzhiqiang
    *Created on 2017/12/22 17:22
    */

    private void addExpenseCost(){
        LayoutInflater layoutInflater = getLayoutInflater();
        View view = layoutInflater.inflate(R.layout.lay_expensecost, null);
        lay_main.addView(view);
        TextView tv_department_name = (TextView)view.findViewById(R.id.tv_department_name);
        TextView tv_expenseaccount_num = (TextView)view.findViewById(R.id.tv_expenseaccount_num);
        TextView tv_date = (TextView)view.findViewById(R.id.tv_date);
        TextView tv_borrowingMoney = (TextView)view.findViewById(R.id.tv_borrowingMoney);
        TextView tv_money = (TextView)view.findViewById(R.id.tv_money);
        TextView tv_isWithholding = (TextView)view.findViewById(R.id.tv_isWithholding);
        final TextView tv_enclosureNum = (TextView)view.findViewById(R.id.tv_enclosureNum);


        tv_department_name.setText(reimbursementVoInfo.getDepartmentName());
        tv_expenseaccount_num.setText(reimbursementVoInfo.getReimbursementCode());
        tv_date.setText(reimbursementVoInfo.getReimbursementDate());
        if (reimbursementVoInfo.getBorrowingMoney()!=null){
            tv_borrowingMoney.setText("￥"+format.format(reimbursementVoInfo.getBorrowingMoney()));

        }
        if (reimbursementVoInfo.getMoney()!=null){
            tv_money.setText("￥"+format.format(reimbursementVoInfo.getMoney()));

        }
        int aaa = reimbursementVoInfo.getIsWithholding();
        if(reimbursementVoInfo.getIsWithholding()==2){
            tv_isWithholding.setText("是");
        }else{
            tv_isWithholding.setText("否");
        }
        tv_enclosureNum.setText(reimbursementVoInfo.getEnclosureNum());
        tv_enclosureNum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!isNull(tv_enclosureNum)) {
                    if (!reimbursementVoInfo.getEnclosureNum().equals(0)) {
                        Intent intent = new Intent();
                        intent.setClass(getApplicationContext(), ShowImageActivity.class);
                        Bundle bundle = new Bundle();
                        intent.putExtra("who", who);
                        intent.putExtra("ProcessState", String.valueOf( reimbursementVoInfo.getProcessState()));
                        bundle.putSerializable("ReimbursementVoInfo", newInfo);
                        intent.putExtras(bundle);
                        startActivityForResult(intent, 1);
                    }
                }
            }
        });
    }

    /**
    *添加差旅View
    *@author Wangzhiqiang
    *Created on 2017/12/23 13:33
    */
    private void addTravelExpense(){
        LayoutInflater layoutInflater = getLayoutInflater();
        View view = layoutInflater.inflate(R.layout.lay_travelexpense, null);
        lay_main.addView(view);

        TextView tv_department_name = (TextView)view.findViewById(R.id.tv_department_name);
        TextView tv_expenseaccount_num = (TextView)view.findViewById(R.id.tv_expenseaccount_num);
        TextView tv_bxr = (TextView)view.findViewById(R.id.tv_bxr);
        TextView tv_date = (TextView)view.findViewById(R.id.tv_date);
        TextView tv_travelpeople = (TextView)view.findViewById(R.id.tv_travelpeople);
        TextView tv_level = (TextView)view.findViewById(R.id.tv_level);
        TextView tv_zq = (TextView)view.findViewById(R.id.tv_zq);
        TextView tv_reason= (TextView)view.findViewById(R.id.tv_reason);
        TextView tv_money= (TextView)view.findViewById(R.id.tv_money);
        final TextView tv_enclosureNum = (TextView)view.findViewById(R.id.tv_enclosureNum);

        tv_department_name.setText(reimbursementVoInfo.getDepartmentName());
        tv_expenseaccount_num.setText(reimbursementVoInfo.getReimbursementCode());
        tv_bxr.setText(reimbursementVoInfo.getProposer());
        tv_date.setText(reimbursementVoInfo.getReimbursementDate());
        tv_travelpeople.setText(reimbursementVoInfo.getTravelUsers());
        tv_level.setText(reimbursementVoInfo.getPositionLeave());
        tv_zq.setText(reimbursementVoInfo.getAttributionDate());
        tv_reason.setText(reimbursementVoInfo.getTravelReason());
        if (reimbursementVoInfo.getMoney()!=null){
            tv_money.setText("￥"+format.format(reimbursementVoInfo.getMoney()));
        }
        tv_enclosureNum.setText(reimbursementVoInfo.getEnclosureNum());
        tv_enclosureNum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!isNull(tv_enclosureNum)) {
                    if (!reimbursementVoInfo.getEnclosureNum().equals(0)) {
                        Intent intent = new Intent();
                        intent.setClass(getApplicationContext(), ShowImageActivity.class);
                        Bundle bundle = new Bundle();
                        intent.putExtra("who", who);
                        intent.putExtra("ProcessState", String.valueOf( reimbursementVoInfo.getProcessState()));

                        bundle.putSerializable("ReimbursementVoInfo", newInfo);
                        intent.putExtras(bundle);
                        startActivityForResult(intent, 1);
                    }
                }
            }
        });
    }

    /**
     *添加借款View
     *@author Wangzhiqiang
     *Created on 2017/12/23 14:42
     */
   private void addBorrowing(){
       LayoutInflater layoutInflater = getLayoutInflater();
       view = layoutInflater.inflate(R.layout.lay_borrowing, null);
       lay_main.addView(view);
       TextView tv_expenseaccount_num = (TextView)view.findViewById(R.id.tv_expenseaccount_num);
       TextView tv_date = (TextView)view.findViewById(R.id.tv_date);
       final TextView tv_enclosureNum = (TextView)view.findViewById(R.id.tv_enclosureNum);


       tv_expenseaccount_num.setText(reimbursementVoInfo.getReimbursementCode());
       tv_date.setText(reimbursementVoInfo.getReimbursementDate());
       tv_enclosureNum.setText(reimbursementVoInfo.getEnclosureNum());
       tv_enclosureNum.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               if(!isNull(tv_enclosureNum)) {
                   if (!reimbursementVoInfo.getEnclosureNum().equals(0)) {
                       Intent intent = new Intent();
                       intent.setClass(getApplicationContext(), ShowImageActivity.class);
                       Bundle bundle = new Bundle();
                       intent.putExtra("who", who);
                       intent.putExtra("ProcessState", String.valueOf( reimbursementVoInfo.getProcessState()));
                       bundle.putSerializable("ReimbursementVoInfo", newInfo);
                       intent.putExtras(bundle);
                       startActivityForResult(intent, 1);
                   }
               }
           }
       });
   }
   
   /**
   *添加奖励扣款View
   *@author Wangzhiqiang
   *Created on 2017/12/23 14:58
   */

   private void addRewardDeduction(){
       LayoutInflater layoutInflater = getLayoutInflater();
       View view = layoutInflater.inflate(R.layout.lay_addrewarddeduction, null);
       lay_main.addView(view);
       TextView tv_expenseaccount_num = (TextView)view.findViewById(R.id.tv_expenseaccount_num);
       TextView tv_date = (TextView)view.findViewById(R.id.tv_date);
       TextView tv_department_name = (TextView)view.findViewById(R.id.tv_department_name);
       TextView tv_hj= (TextView)view.findViewById(R.id.tv_hj);
       final TextView tv_enclosureNum = (TextView)view.findViewById(R.id.tv_enclosureNum);


       tv_expenseaccount_num.setText(reimbursementVoInfo.getReimbursementCode());
       tv_date.setText(reimbursementVoInfo.getReimbursementDate());
       tv_department_name.setText(reimbursementVoInfo.getDepartmentName());
       if (reimbursementVoInfo.getMoney()!=null){
           tv_hj.setText("￥"+format.format(reimbursementVoInfo.getMoney()));
       }
       tv_enclosureNum.setText(reimbursementVoInfo.getEnclosureNum());
       tv_enclosureNum.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               if(!isNull(tv_enclosureNum)) {
                   if (!reimbursementVoInfo.getEnclosureNum().equals(0)) {
                       Intent intent = new Intent();
                       intent.setClass(getApplicationContext(), ShowImageActivity.class);
                       Bundle bundle = new Bundle();
                       intent.putExtra("who", who);
                       intent.putExtra("ProcessState", String.valueOf( reimbursementVoInfo.getProcessState()));
                       bundle.putSerializable("ReimbursementVoInfo", newInfo);
                       intent.putExtras(bundle);
                       startActivityForResult(intent, 1);
                   }
               }
           }
       });
   }

    /**
    *添加成本费用报销明细
    *@author Wangzhiqiang
    *Created on 2017/12/22 18:09
    */
    private void addExpenseCostFormDetailVoInfo(){
        layout_ExpenseCostFormDetail.setVisibility(View.VISIBLE);
        rv_ExpenseCostFormDetail.setLayoutManager(new LinearLayoutManager(mContext));
        rv_ExpenseCostFormDetail.setHasFixedSize(true);
        rv_ExpenseCostFormDetail.setItemAnimator(new DefaultItemAnimator());

        ExpenseCostAdapter expenseCostAdapter = new ExpenseCostAdapter(ls_ExpenseCostFormDetailVoInfo,mContext);
        rv_ExpenseCostFormDetail.setAdapter(expenseCostAdapter);
    }


    /**
    *添加差旅费用报销明细
    *@author Wangzhiqiang
    *Created on 2017/12/22 18:23
    */
    private void addtravelExpensesFormDetail(){
        layout_travelExpensesFormDetail.setVisibility(View.VISIBLE);
        rv_travelExpensesFormDetail.setLayoutManager(new LinearLayoutManager(mContext));
        rv_travelExpensesFormDetail.setHasFixedSize(true);
        rv_travelExpensesFormDetail.setItemAnimator(new DefaultItemAnimator());

        TravelExpensesFormDetailAdapter travelExpensesFormDetailAdapter = new TravelExpensesFormDetailAdapter(ls_TravelExpensesFormDetailVoInfo,mContext);
        rv_travelExpensesFormDetail.setAdapter(travelExpensesFormDetailAdapter);
    }
    
    /**
    *添加部门明细
    *@author Wangzhiqiang
    *Created on 2017/12/22 18:27
    */

    private void addbearDepartment(){
        layout_bearDepartment.setVisibility(View.VISIBLE);
        rv_bearDepartment.setLayoutManager(new LinearLayoutManager(mContext));
        rv_bearDepartment.setHasFixedSize(true);
        rv_bearDepartment.setItemAnimator(new DefaultItemAnimator());

        BearDepartmentAdapter bearDepartmentAdapter = new BearDepartmentAdapter(ls_BearDepartmentVoInfo,mContext);
        rv_bearDepartment.setAdapter(bearDepartmentAdapter);
    }

    /**
    *添加奖励扣款明细
    *@author Wangzhiqiang
    *Created on 2017/12/23 15:49
    */

    private void addRewardDeductionVoInfo(){
        layout_rewardDeduction.setVisibility(View.VISIBLE);
        rv_rewardDeduction.setLayoutManager(new LinearLayoutManager(mContext));
        rv_rewardDeduction.setHasFixedSize(true);
        rv_rewardDeduction.setItemAnimator(new DefaultItemAnimator());

        RewardAdapter rewardAdapter = new RewardAdapter(ls_RewardDeductionVoInfo,mContext);
        rv_rewardDeduction.setAdapter(rewardAdapter);

     }

     /**
     *添加收款人明细
     *@author Wangzhiqiang
     *Created on 2017/12/23 16:05
     */
     private void addPayeeInfo(){
         layout_payee.setVisibility(View.VISIBLE);
         rv_payee.setLayoutManager(new LinearLayoutManager(mContext));
         rv_payee.setHasFixedSize(true);
         rv_payee.setItemAnimator(new DefaultItemAnimator());

         PaypeeAdapter payeeAdapter = new PaypeeAdapter(ls_PayeeInfo,mContext,type);
         rv_payee.setAdapter(payeeAdapter);
     }

    /**
     *显示一个按钮
     *@author Wangzhiqiang
     *Created on 2017/12/22 18:58
     */

    private void showBtn6(){
        layout_btn6.setVisibility(View.VISIBLE);
        nextAuditorId = "";
        Button btn_sure = (Button)findViewById(R.id.btn_sp);
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                suredata();
            }
        });
    }
    /**
    *显示一个按钮
    *@author Wangzhiqiang
    *Created on 2017/12/22 18:58
    */

    private void showBtn1(){
        layout_btn1.setVisibility(View.VISIBLE);
        layout_shr.setVisibility(View.VISIBLE);
        tv_shr = (TextView)findViewById(R.id.tv_shr);
        tv_shr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent2 = new Intent();
                intent2.setClass(mContext, AuditorActivity.class);
                intent2.putExtra("index",id);
                startActivityForResult(intent2, 1);            }
        });
        Button btn_sure = (Button)findViewById(R.id.btn_sure);
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isNull(tv_shr)){
                    Toast.makeText(mContext, "请选择下一审核人！", Toast.LENGTH_SHORT).show();
                    return;
                }
                suredata();
            }
        });
    }
    /**
     *显示两个按钮
     *@author Wangzhiqiang
     *Created on 2017/12/22 19:00
     */
    private void showBtn7(){
        layout_btn7.setVisibility(View.VISIBLE);
        ed_remarks = (EditText) findViewById(R.id.ed_remark);
        nextAuditorId = "";
        Button btn_sh = (Button)findViewById(R.id.btn_sp7);
        btn_sh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                suredata();
            }
        });

        Button btn_bh = (Button)findViewById(R.id.btn_bx7);
        btn_bh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isNull(ed_remarks)){
                    Toast.makeText(mContext, "请填写备注！", Toast.LENGTH_SHORT).show();
                    return;
                }
                rejectData();
            }
        });
    }

    /**
    *显示两个按钮
    *@author Wangzhiqiang
    *Created on 2017/12/22 19:00
    */
    private void showBtn2(){
        layout_btn2.setVisibility(View.VISIBLE);
        layout_shr.setVisibility(View.VISIBLE);
        tv_shr = (TextView)findViewById(R.id.tv_shr);
        ed_remarks = (EditText) findViewById(R.id.ed_remarks);
        tv_shr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent2 = new Intent();
                intent2.setClass(mContext, AuditorActivity.class);
                intent2.putExtra("index",id);
                startActivityForResult(intent2, 1);            }
        });
        Button btn_sh = (Button)findViewById(R.id.btn_sh);
        btn_sh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isNull(tv_shr)){
                    Toast.makeText(mContext, "请选择下一审核人！", Toast.LENGTH_SHORT).show();
                    return;
                }
                suredata();
            }
        });

        Button btn_bh = (Button)findViewById(R.id.btn_sc);
        btn_bh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isNull(ed_remarks)){
                    Toast.makeText(mContext, "请填写备注！", Toast.LENGTH_SHORT).show();
                    return;
                }
              rejectData();
            }
        });
    }

    /**
     *显示一个按钮
     *@author Wangzhiqiang
     *Created on 2017/12/22 18:58
     */

    private void showBtn3(){
        layout_btn3.setVisibility(View.VISIBLE);
        layout_shr.setVisibility(View.VISIBLE);
        tv_shr = (TextView)findViewById(R.id.tv_shr);
        tv_shr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent2 = new Intent();
                intent2.setClass(mContext, AuditorActivity.class);
                intent2.putExtra("index",id);
                startActivityForResult(intent2, 1);            }
        });
        Button btn_sure = (Button)findViewById(R.id.btn_tj);
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(isNull(tv_shr)){
                    Toast.makeText(mContext, "请选择审核人", Toast.LENGTH_SHORT).show();
                    return;
                }
                sendExpense();
            }
        });
    }
    /**
     *显示一个按钮
     *@author Wangzhiqiang
     *Created on 2017/12/22 18:58
     */

    private void showBtn4(){

        layout_btn4.setVisibility(View.VISIBLE);
        Button btn_sure = (Button)findViewById(R.id.btn_xg);
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mContext, "正在开发...", Toast.LENGTH_SHORT).show();
                return;

            }
        });
    }

    /**
    *审核的数据请求
    *@author Wangzhiqiang
    *Created on 2017/12/23 16:09
    */

    private void suredata(){

        mProgressDialog = ProgressDialog.show(mContext, null, "正在加载中...");
        mProgressDialog.setCancelable(true);
        mProgressDialog.setCanceledOnTouchOutside(false);

        mOkHttpClient = new OkHttpClient();

        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("nextAuditorId", nextAuditorId);
        String json1 = JSON.toJSONString(map);
        RequestBody formBody =  FormBody.create(MediaType.parse("application/json;charset=UTF-8"),json1);
        String s = MyApplication.getMsession();
        Request request = new Request.Builder()
                .url(IpUtil.getIP()+"/reimbursement/reimbursement/examine")
                .header("cookie", MyApplication.getMsession())
                .addHeader("Content-Type","application/json;charset=UTF-8")
                .post(formBody)
                .build();

        Call call = mOkHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(mContext, "连接异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String str = response.body().string();
                if(str.indexOf("success")>=0) {

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "操作成功", Toast.LENGTH_SHORT).show();
                            Intent mIntent = new Intent();
                            setResult(1, mIntent);
                            finish();
                        }
                    });
                }
            }

        });

    }
    
    /**
    *驳回的数据请求
    *@author Wangzhiqiang
    *Created on 2017/12/23 16:17
    */

    private void rejectData(){
        mProgressDialog = ProgressDialog.show(mContext, null, "正在加载中...");
        mProgressDialog.setCancelable(true);
        mProgressDialog.setCanceledOnTouchOutside(false);

        mOkHttpClient = new OkHttpClient();
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("remarks", ed_remarks.getText().toString());
        String json1 = JSON.toJSONString(map);
        RequestBody formBody =  FormBody.create(MediaType.parse("application/json;charset=UTF-8"),json1);
        String s = MyApplication.getMsession();
        Request request = new Request.Builder()
                .url(IpUtil.getIP()+"/reimbursement/reimbursement/reject")
                .header("cookie", MyApplication.getMsession())
                .addHeader("Content-Type","application/json;charset=UTF-8")
                .post(formBody)
                .build();
        Call call = mOkHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(mContext, "连接异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String str = response.body().string();
                if(str.indexOf("success")>=0) {

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "操作成功", Toast.LENGTH_SHORT).show();
                            Intent mIntent = new Intent();
                            setResult(1, mIntent);
                            finish();
                        }
                    });
                }
            }

        });

    }

    /**
     *获取数据
     *@author Wangzhiqiang
     *Created on 2017/12/21 18:58
     */
    private void getdata(){
        mProgressDialog = ProgressDialog.show(mContext, null, "正在加载中...");
        mProgressDialog.setCancelable(true);
        mProgressDialog.setCanceledOnTouchOutside(false);
        mOkHttpClient = new OkHttpClient();
        String id = reimbursementVoInfo.getId();
        Request request = new Request.Builder()
                .url(IpUtil.getIP()+"/reimbursement/reimbursement/getReimbursementById/"+reimbursementVoInfo.getId())
                .header("cookie", MyApplication.getMsession())
                .build();

        Call call = mOkHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                mProgressDialog.dismiss();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(mContext, "连接异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                mProgressDialog.dismiss();
                String str = response.body().string();
                if(str.indexOf("reimbursementCode")>=0) {
                    newInfo = JsonUtil.getPerson(str, ReimbursementVoInfo.class);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            showDate(newInfo);
                        }
                    });

                }else{
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "查询报销单信息出现错误", Toast.LENGTH_SHORT).show();

                        }
                    });
                }
            }
        });

    }

    private void showDate(ReimbursementVoInfo reimbursementVoInfo ){
        /**判断是否有费用成本明细*/
        ls_ExpenseCostFormDetailVoInfo =new ArrayList<>();
        ls_ExpenseCostFormDetailVoInfo = reimbursementVoInfo.getExpenseCostFormDetailVoList();
        if(ls_ExpenseCostFormDetailVoInfo!=null){
            if(ls_ExpenseCostFormDetailVoInfo.size()>0){
                addExpenseCostFormDetailVoInfo();
            }
        }

        /**判断是否有差旅明细*/
        ls_TravelExpensesFormDetailVoInfo = new ArrayList<>();
        ls_TravelExpensesFormDetailVoInfo = reimbursementVoInfo.getTravelExpensesFormDetailVoList();
        if(ls_TravelExpensesFormDetailVoInfo!=null){
            if(ls_TravelExpensesFormDetailVoInfo.size()>0){
                addtravelExpensesFormDetail();
            }
        }

//        /**判断是否有收款部门明细*/
//        ls_BearDepartmentVoInfo = new ArrayList<>();
//        ls_BearDepartmentVoInfo = reimbursementVoInfo.getBearDepartmentVoList();
//        if(ls_BearDepartmentVoInfo!=null){
//            if(ls_BearDepartmentVoInfo.size()>0){
//                addbearDepartment();
//            }
//        }

        /**判断是否有奖励扣款明细*/
        ls_RewardDeductionVoInfo = new ArrayList<>();
        ls_RewardDeductionVoInfo = reimbursementVoInfo.getRewardDeductionVoList();
        if(ls_RewardDeductionVoInfo!=null){
            if(ls_RewardDeductionVoInfo.size()>0){
                addRewardDeductionVoInfo();
            }
        }


        /**判断是否有借款单明细*/

        BorrowingVoInfo info = new BorrowingVoInfo();
        if (reimbursementVoInfo.getBorrowingVoList()==null){

        }else {
            LinearLayout layout_bow = (LinearLayout)view.findViewById(R.id.layout_brow);
            layout_bow.setVisibility(View.VISIBLE);
            LayoutInflater layoutInflater = getLayoutInflater();
            View view1 = layoutInflater.inflate(R.layout.lay_bow, null);
            layout_bow.addView(view1);
            TextView tv_jkr= (TextView)view1.findViewById(R.id.tv_jkr);
            TextView tv_department_name = (TextView)view1.findViewById(R.id.tv_department_name);
            TextView tv_xm = (TextView)view1.findViewById(R.id.tv_xm);
            TextView tv_hktime = (TextView)view1.findViewById(R.id.tv_hktime);
            TextView tv_jkmoney = (TextView)view1.findViewById(R.id.tv_jkmoney);

            info = reimbursementVoInfo.getBorrowingVoList();
            tv_jkr.setText(info.getBorrowerName());
            tv_department_name.setText(info.getDepartmentName());
            tv_xm.setText(info.getLoanProject());
            tv_hktime.setText(info.getRepaymentDate());
            tv_jkmoney.setText("￥"+format.format(info.getLoanMoney()));
        }

        /**判断是否有收款人明细*/
        ls_PayeeInfo = new ArrayList<>();
        ls_PayeeInfo = reimbursementVoInfo.getPayeeList();
        if(ls_PayeeInfo!=null){
            if(ls_PayeeInfo.size()>0){
                addPayeeInfo();
            }
        }
    }

    /**
     *申请报销单数据请求
     *@author Wangzhiqiang
     *Created on 2017/12/21 10:21
     */
    private void sendExpense(){

        mProgressDialog = ProgressDialog.show(mContext, null, "正在加载中...");
        mProgressDialog.setCancelable(true);
        mProgressDialog.setCanceledOnTouchOutside(false);

        mOkHttpClient = new OkHttpClient();
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("nextAuditorId", nextAuditorId);
        String json1 = JSON.toJSONString(map);
        RequestBody formBody =  FormBody.create(MediaType.parse("application/json;charset=UTF-8"),json1);
        String s = MyApplication.getMsession();
        Request request = new Request.Builder()
                .url(IpUtil.getIP()+"/reimbursement/reimbursement/submitReimbursement")
                .header("cookie", MyApplication.getMsession())
                .addHeader("Content-Type","application/json;charset=UTF-8")
                .post(formBody)
                .build();
        Call call = mOkHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                mProgressDialog.dismiss();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(mContext, "连接服务器异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                mProgressDialog.dismiss();

                String str = response.body().string();
                //{"messageType":2,"type":"success","title":"操作信息","message":"提交成功","data":null}
                if(str.indexOf("success")>=0){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "提交成功", Toast.LENGTH_SHORT).show();
                            finish();

                        }
                    });
                }else {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "提交失败", Toast.LENGTH_SHORT).show();
                        }
                    });
                }

            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

      if (resultCode == 8){
            String name = data.getExtras().getString("name");
            nextAuditorId = data.getExtras().getString("id");
            tv_shr.setText(name);
        }
        if (resultCode == 1){
            newInfo = (ReimbursementVoInfo)data.getExtras().get("ReimbursementVoInfo");
        }
    }
}
